# Definition for singly-linked list.
"""
给定一个排序链表，删除所有含有重复数字的节点，只保留原始链表中 没有重复出现 的数字。
输入: 1->2->3->3->4->4->5
输出: 1->2->5
"""


class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution:
    def deleteDuplicates(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        cur = head
        res = ListNode(None)
        res.next = head
        prev = res
        while cur:
            deleted = False
            while cur.next and cur.val == cur.next.val:
                cur.next = cur.next.next
                deleted = True
            if deleted:
                prev.next = cur.next
            else:
                prev = cur
            cur = cur.next
        return res.next


a1 = ListNode(1)
a2 = ListNode(1)
a3 = ListNode(2)
a4 = ListNode(2)
a5 = ListNode(3)
a1.next = a2
a2.next = a3
a3.next = a4
a4.next = a5
s = Solution()
res = s.deleteDuplicates(a1)
while res:
    print(res.val)
    res = res.next